
import { CommonSimulator as AbaqusSimulator, SimulationJobResult } from '../common/simulator';
import { simServerInit } from './simulationServer';
import { SimulationConfigCache } from '../common/cache';

export const simulator = new AbaqusSimulator();

async function bootstrap() {
  await SimulationConfigCache.init();
  simServerInit();

  simulator.on('sim:succeed', (businessId, parameters, result: SimulationJobResult) => {
    console.info(`simulation(id=${businessId}) succeed`);
  });

  simulator.on('sim:failed', (businessId, error) => {
    console.error(`simulation(id=${businessId}) failed: ${error}`);
  });

}

bootstrap().catch(e => {
  console.error(`abaqus interface bootstrap failed: ${e.message}`);
  process.exit(-1);
});
